package org.lee.fms.web;

import org.lee.fms.vo.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * FreeMarkerServlet
 *
 * @author dralee
 * @date 2021-12-29 09:30:13
 **/
@WebServlet(name = "myFreeMarkerServlet", urlPatterns = {"/"})
public class MyFreeMarkerServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=UTF-8");
        List<User> users = new ArrayList<>();
        users.add(User.builder().name("Kate").age(12).job("child").amount(BigDecimal.valueOf(200.5)).build());
        users.add(User.builder().name("Jim").age(22).job("student").amount(BigDecimal.valueOf(1200.98)).build());
        users.add(User.builder().name("Tom").age(32).job("teacher").amount(BigDecimal.valueOf(8500.99)).build());
        req.setAttribute("users", users);
        req.getRequestDispatcher("/index.ftl").forward(req, resp);
    }
}
